package com.哈希表;

import java.util.HashMap;
import java.util.Map;

public class 只出现一次的数字 {
    static class Solution {
        public int singleNumber(int[] nums) {
            //自定义map
            //MyHashMap myHashMap = new MyHashMap();
            //内置map
            Map<Integer,Integer> myHashMap = new HashMap();
            for(int i :nums){
                if(myHashMap.containsKey(i)){
                    int count = myHashMap.get(i);
                    myHashMap.put(i,++count);
                }
                else{
                    myHashMap.put(i,1);
                }
            }
            int num = 0;
            for(int i : nums){
                if(myHashMap.get(i)==1){
                    num = i;
                    break;
                }
            }
            return num;
        }

        public static void main(String[] args) {
            Solution solution = new Solution();
            System.out.println(solution.singleNumber(new int[]{1,2,3,4,1,2,3,4,5,6,5}));
        }
    }

}
